package com.pureut.order.service.impl;


import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pureut.common.core.exception.GlobalException;
import com.pureut.common.core.utils.StringUtils;
import com.pureut.common.core.utils.bean.BeanUtils;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.datascope.annotation.DataScope;
import com.pureut.common.security.utils.DictUtils;
import com.pureut.common.security.utils.SecurityUtils;
import com.pureut.order.domain.OrderSupplierManagement;
import com.pureut.order.domain.PurchaseOrder;
import com.pureut.order.dto.OrderSupplierManagementDto;
import com.pureut.order.dto.OrderSupplierManagementMqDto;
import com.pureut.order.export.OrderSupplierManagementExport;
import com.pureut.order.export.OrderSupplierManagementimportExport;
import com.pureut.order.mapper.OrderSupplierManagementMapper;
import com.pureut.order.mapper.PurchaseOrderMapper;
import com.pureut.order.service.OrderSupplierManagementService;
import com.pureut.order.util.VariousMqUtil;
import com.pureut.order.vo.OrderReviewVo;
import com.pureut.order.vo.OrderSupplierManagementVo;
import com.pureut.system.api.FeignService;
import com.pureut.system.api.OrderFeignService;
import com.pureut.system.api.domain.SysDictData;
import com.pureut.system.api.domain.SysUser;
import com.pureut.system.api.vo.SysAuditHistoryVo;
import com.pureut.system.api.vo.SysWorkbenchAuditAgentVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;

@Slf4j
@Service
public class OrderSupplierManagementServiceImpl extends ServiceImpl<OrderSupplierManagementMapper, OrderSupplierManagement> implements OrderSupplierManagementService {

    @Resource
    OrderSupplierManagementMapper orderSupplierManagementMapper;

    @Resource
    FeignService feignService;

    @Resource
    OrderFeignService orderFeignService;

    @Resource
    PurchaseOrderMapper purchaseOrderMapper;

    /**
     * 供应商分页查询
     *
     * @param orderSupplierManagementVo
     * @return
     */
    @Override
    @DataScope(deptAlias = "order_supplier_management")
    public List<OrderSupplierManagementDto> getList(OrderSupplierManagementVo orderSupplierManagementVo) {
        List<OrderSupplierManagementDto> allList = orderSupplierManagementMapper.getAllList(orderSupplierManagementVo);
        //获取供应商状态缓存字典数据
        List<SysDictData> statusArray = DictUtils.getDictCache("order_supplier_status");
        Map<String, String> statusMap = statusArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
        //获取供应商所属机构缓存字典数据
        List<SysDictData> organizationArray = DictUtils.getDictCache("order_affiliated_organization");
        Map<String, String> organizationMap = organizationArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
        //获取供应商等级缓存字典数据
        List<SysDictData> levelArray = DictUtils.getDictCache("order_supplier_level");
        Map<String, String> levelMap = levelArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
        for (OrderSupplierManagementDto entity : allList) {
            //获取供应商状态缓存字典数据
            entity.setAuditStatusDict(statusMap.get(entity.getAuditStatus()));
            //获取供应商所属机构缓存字典数据
//            entity.setAffiliatedOrganizationDict(organizationMap.get(entity.getAffiliatedOrganization()));
            //获取供应商等级缓存字典数据
            entity.setSupplierLevelDict(levelMap.get(entity.getSupplierLevel()));
            //归属人
            String ascriptionBy = entity.getAscriptionBy();
            entity.setAscriptionBy(feignService.getUserName(Long.valueOf(ascriptionBy)));
        }
        return allList;
    }

    /**
     * 新增供应商
     *
     * @param orderSupplierManagementVo
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean addSupplier(OrderSupplierManagementVo orderSupplierManagementVo) throws Exception {
        //判断简称是否存在
        OrderSupplierManagement orderSupplierManagementOne = getOne(new QueryWrapper<OrderSupplierManagement>().lambda().eq(OrderSupplierManagement::getSupplierAbbreviation, orderSupplierManagementVo.getSupplierAbbreviation()));
        if (orderSupplierManagementOne != null) {
            throw new GlobalException("该供应商简称已经存在");
        }
        OrderSupplierManagement orderSupplierManagement = new OrderSupplierManagement();
        orderSupplierManagement.setDeptId(SecurityUtils.getDeptId());
        orderSupplierManagement.setSupplierName(orderSupplierManagementVo.getSupplierName());
        orderSupplierManagement.setSupplierAbbreviation(orderSupplierManagementVo.getSupplierAbbreviation());
        String authorityCoding = feignService.getAuthorityCoding("order:supplier:list");
        if (authorityCoding == null) {
            throw new GlobalException("未进行单据配置,单据编码生成失败");
        }
        orderSupplierManagement.setSupplierNum(authorityCoding);
        orderSupplierManagement.setSupplierLevel(Integer.parseInt(orderSupplierManagementVo.getSupplierLevel()));
        orderSupplierManagement.setCreateBy(SecurityUtils.getUsername());
        orderSupplierManagement.setContactsBy(orderSupplierManagementVo.getContactsBy());
        orderSupplierManagement.setContactsInformation(orderSupplierManagementVo.getContactsInformation());
        orderSupplierManagement.setSupplierAddress(orderSupplierManagementVo.getSupplierAddress());
        orderSupplierManagement.setInvoicingInformation(orderSupplierManagementVo.getInvoicingInformation());
        orderSupplierManagement.setBusinessLicense(orderSupplierManagementVo.getBusinessLicense());
        orderSupplierManagement.setAuditStatus(2);
        orderSupplierManagement.setCreateTime(new Date());
        orderSupplierManagement.setRemark(orderSupplierManagementVo.getRemark());
        if (!("".equals(orderSupplierManagementVo.getAscriptionBy()))) {
            orderSupplierManagement.setAscriptionBy(Integer.parseInt(orderSupplierManagementVo.getAscriptionBy()));
        }

        //mq发送消息
        OrderSupplierManagementMqDto orderSupplierManagementMqDto = new OrderSupplierManagementMqDto();
        BeanUtils.copyProperties(orderSupplierManagement, orderSupplierManagementMqDto);
        VariousMqUtil.orderSupplierManagementMqSend(orderSupplierManagementMqDto);
        return save(orderSupplierManagement);
    }

    /**
     * 冻结供应商
     */
    @Override
    public boolean frozenSupplier(Long id) {
        //获取供应商信息
        OrderSupplierManagement orderSupplierManagement = getById(id);
        if (orderSupplierManagement.getAuditStatus() == 4) {
            orderSupplierManagement.setAuditStatus(6);
            return updateById(orderSupplierManagement);
        } else {
            throw new GlobalException("只能冻结启用的供应商");
        }

    }

    /**
     * 解冻供应商
     *
     * @param id
     * @return
     */
    @Override
    public boolean thawSupplier(Long id) {
        //获取供应商信息
        OrderSupplierManagement orderSupplierManagement = getById(id);
        if (orderSupplierManagement.getAuditStatus() == 6) {
            orderSupplierManagement.setAuditStatus(4);
            return updateById(orderSupplierManagement);
        } else {
            throw new GlobalException("只能解冻已冻结的供应商");
        }

    }

    /**
     * 撤销审核
     *
     * @param id
     * @return
     */
    @Override
    public boolean revokeApproval(Long id) {
        //获取供应商信息
        OrderSupplierManagement orderSupplierManagement = getById(id);
        if (orderSupplierManagement.getAuditStatus() == 1) {
            orderSupplierManagement.setAuditStatus(2);

            //删除审核代办消息提醒
            feignService.deleteDoc(orderSupplierManagement.getSupplierNum(),"供应商管理");

            return updateById(orderSupplierManagement);
        } else {
            throw new GlobalException("只能撤销待审核的数据");
        }

    }

    /**
     * 获取导出数据列表
     *
     * @param orderSupplierManagementVo
     * @return
     */
    @Override
    public List<OrderSupplierManagementExport> getInfoExport(OrderSupplierManagementVo orderSupplierManagementVo) {
        List<OrderSupplierManagementExport> exportList;
        //获取供应商状态缓存字典数据
        List<SysDictData> statusArray = DictUtils.getDictCache("order_supplier_status");
        Map<String, String> statusMap = statusArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        //获取供应商等级缓存字典数据
        List<SysDictData> levelArray = DictUtils.getDictCache("order_supplier_level");
        Map<String, String> levelMap = levelArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        if (orderSupplierManagementVo.getIdStr() == null) {
            exportList = orderSupplierManagementMapper.getExportList(orderSupplierManagementVo);
        } else {
            List<String> idList = Arrays.asList(orderSupplierManagementVo.getIdStr());
            exportList = orderSupplierManagementMapper.getDataByIdStr(idList);
        }
        for (OrderSupplierManagementExport entity : exportList) {
            //状态
            entity.setAuditStatus(statusMap.get(entity.getAuditStatus()));
            //等级
            entity.setSupplierLevel(levelMap.get(entity.getSupplierLevel()));
            if (entity.getAscriptionBy() != null) {
                //归属人
                String ascriptionBy = entity.getAscriptionBy();
                entity.setAscriptionBy(feignService.getUserName(Long.valueOf(ascriptionBy)));
            }
        }
        return exportList;
    }

    /**
     * 导入
     *
     * @param coCustomer
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public String importMouldData(List<OrderSupplierManagementimportExport> coCustomer) {
        if (StringUtils.isNull(coCustomer) || coCustomer.size() == 0) {
            throw new GlobalException("导入供应商信息不能为空！");
        }
        int successNum = 0;
        int failureNum = 0;
        StringBuilder successMsg = new StringBuilder();
        StringBuilder failureMsg = new StringBuilder();
        //获取供应商等级缓存字典数据
        List<SysDictData> levelArray = DictUtils.getDictCache("order_supplier_level");
        Map<String, String> levelMap = levelArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        for (OrderSupplierManagementimportExport mouldModelExport : coCustomer) {
            OrderSupplierManagement orderSupplierManagement = new OrderSupplierManagement();
            try {
                if (mouldModelExport.getSupplierName() == null || mouldModelExport.getSupplierAbbreviation() == null || mouldModelExport.getSupplierLevel() == null) {
                    throw new GlobalException("存在必填字段为空，请核实");
                }

                //校验加工商简称是否为空
                boolean matches = mouldModelExport.getSupplierAbbreviation().matches("[A-Z]{0,4}");
                if (!matches){
                    throw new GlobalException("供应商简称必须为4位大写字母");
                }

                // 赋值
                orderSupplierManagement.setSupplierName(mouldModelExport.getSupplierName());
                orderSupplierManagement.setContactsBy(mouldModelExport.getContactsBy());
                orderSupplierManagement.setContactsInformation(mouldModelExport.getContactsInformation());
                orderSupplierManagement.setSupplierAddress(mouldModelExport.getSupplierAddress());
                //判断简称是否唯一
                OrderSupplierManagement orderSupplierManagementOne = getOne(new QueryWrapper<OrderSupplierManagement>().lambda().eq(OrderSupplierManagement::getSupplierAbbreviation, mouldModelExport.getSupplierAbbreviation()));
                if (orderSupplierManagementOne != null) {
                    throw new GlobalException("该供应商简称已经存在");
                }
                orderSupplierManagement.setSupplierAbbreviation(mouldModelExport.getSupplierAbbreviation());
                //供应商等级
                for (Map.Entry<String, String> entry : levelMap.entrySet()) {
                    if (entry.getValue().equals(mouldModelExport.getSupplierLevel())) {
                        orderSupplierManagement.setSupplierLevel(Integer.parseInt(entry.getKey()));
                        break;
                    }
                }
                orderSupplierManagement.setCreateBy(SecurityUtils.getUsername());
                orderSupplierManagement.setAuditStatus(2);
                //获取供应商编码
                String authorityCoding = feignService.getAuthorityCoding("order:supplier:list");
                if (authorityCoding == null) {
                    throw new GlobalException("未进行单据配置,单据编码生成失败");
                }
                orderSupplierManagement.setSupplierNum(authorityCoding);
                orderSupplierManagement.setCreateTime(new Date());
                //判断归属人是否存在

                String userName = mouldModelExport.getAscriptionBy();
                if (userName != null) {
                    AjaxResult byUserName = feignService.getByUserName(userName);
                    if (byUserName == null) {
                        throw new GlobalException("未获取到相关归属人");
                    }
                    SysUser data = JSON.parseObject(JSON.toJSONString(byUserName.get("data")), SysUser.class);
                    orderSupplierManagement.setAscriptionBy(data.getUserId());
                }
                orderSupplierManagement.setDeptId(SecurityUtils.getDeptId());
                save(orderSupplierManagement);

                //mq发送消息
                OrderSupplierManagementMqDto orderSupplierManagementMqDto = new OrderSupplierManagementMqDto();
                BeanUtils.copyProperties(orderSupplierManagement, orderSupplierManagementMqDto);
                VariousMqUtil.orderSupplierManagementMqSend(orderSupplierManagementMqDto);

                successNum++;
                successMsg.append(successNum + "、供应商信息 " + mouldModelExport.getSupplierName() + " 导入成功");

            } catch (Exception e) {
                failureNum++;
                String msg = failureNum + "、供应商 " + mouldModelExport.getSupplierName() + " 导入失败：";
                failureMsg.append(msg + e.getMessage());
            }
        }
        if (failureNum > 0) {
            failureMsg.insert(0, "很抱歉，导入失败！共 " + failureNum + " 条数据格式不正确，错误如下：");
            throw new GlobalException(failureMsg.toString());
        } else {
            successMsg.insert(0, "恭喜您，数据已全部导入成功！共 " + successNum + " 条，数据如下：");
        }

        return successMsg.toString();
    }

    /**
     * 删除供应商
     *
     * @param ids
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean  deleteSupplierByIds(String ids) throws Exception {
        if (ids != null) {
            List<OrderSupplierManagement> orderSupplierManagementList = new ArrayList<>();

            List<String> stringIds = Arrays.asList(ids.split(","));
            //获取供应商列表
            List<OrderSupplierManagement> orderSupplierManagements = orderSupplierManagementMapper.selectBatchIds(stringIds);

            for (OrderSupplierManagement entity : orderSupplierManagements) {
                List<PurchaseOrder> purchaseOrders = purchaseOrderMapper.selectList(new QueryWrapper<PurchaseOrder>().lambda().eq(PurchaseOrder::getSupplierId, entity.getId()));
                //如果没有关联数据，并且状态为已冻结，就放入删除列表
                boolean delData = 6 == entity.getAuditStatus() && purchaseOrders.size() == 0;
                if (delData || entity.getAuditStatus() == 2 || entity.getAuditStatus() == 5) {
                    orderSupplierManagementList.add(entity);

                    feignService.deleteDoc(entity.getSupplierNum(),"供应商管理");

                }
            }

            if (orderSupplierManagementList.size() > 0) {
                StringBuilder stringBuilder = new StringBuilder();
                for (OrderSupplierManagement entity : orderSupplierManagementList) {
                    stringBuilder.append(entity.getSupplierNum()).append(",");
                }
                StringBuilder stringBuilder1 = stringBuilder.deleteCharAt(stringBuilder.length() - 1);
                //mq同步删除加工商
                OrderSupplierManagementMqDto orderSupplierManagementMqDto = new OrderSupplierManagementMqDto();
                orderSupplierManagementMqDto.setSupplierDeleteMark(12);
                orderSupplierManagementMqDto.setSupplierNum(stringBuilder1.toString());
                VariousMqUtil.orderSupplierManagementMqSendDelete(orderSupplierManagementMqDto);
                return removeByIds(orderSupplierManagementList);
            } else {
                throw new GlobalException("只能删除状态为待提交、未通过或者已冻结并且无关联的供应商");
            }
        }
        return false;
    }

    /**
     * 查看供应商信息
     *
     * @param id
     * @return
     */
    @Override
    public OrderSupplierManagementDto getSupplierById(Long id) {
        OrderSupplierManagementDto orderSupplierManagementDto = new OrderSupplierManagementDto();
        OrderSupplierManagement orderSupplierManagement = getById(id);
        BeanUtils.copyProperties(orderSupplierManagement, orderSupplierManagementDto);
        //获取供应商所属机构缓存字典数据
        List<SysDictData> organizationArray = DictUtils.getDictCache("order_affiliated_organization");
        Map<String, String> organizationMap = organizationArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
//        orderSupplierManagementDto.setAffiliatedOrganizationDict(organizationMap.get(String.valueOf(orderSupplierManagement.getAffiliatedOrganization())));
//        orderSupplierManagementDto.setAffiliatedOrganization(String.valueOf(orderSupplierManagement.getAffiliatedOrganization()));
        //获取供应商等级缓存字典数据
        List<SysDictData> levelArray = DictUtils.getDictCache("order_supplier_level");
        Map<String, String> levelMap = levelArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
        orderSupplierManagementDto.setSupplierLevelDict(levelMap.get(String.valueOf(orderSupplierManagement.getSupplierLevel())));
        orderSupplierManagementDto.setSupplierLevel(String.valueOf(orderSupplierManagement.getSupplierLevel()));
        //归属人
        Long userId = orderSupplierManagement.getAscriptionBy();
        String userName = feignService.getUserName(userId);
        orderSupplierManagementDto.setAscriptionBy(String.valueOf(userId));
        orderSupplierManagementDto.setAscriptionByDict(userName);
        return orderSupplierManagementDto;
    }

    /**
     * 提交审核
     *
     * @param id
     * @return
     */
    @Override
    public boolean reivewSubmit(Long id) {
        OrderSupplierManagement orderSupplierManagement = getById(id);
        if (orderSupplierManagement.getAuditStatus() == 2) {
            orderSupplierManagement.setAuditStatus(1);

            //新增审核代办
            SysWorkbenchAuditAgentVo sysWorkbenchAuditAgentVo = new SysWorkbenchAuditAgentVo();

            sysWorkbenchAuditAgentVo.setReceiptName("供应商管理");
            sysWorkbenchAuditAgentVo.setDocConfig("order:purchase:supplier:examine");
            sysWorkbenchAuditAgentVo.setReceiptNumber(orderSupplierManagement.getSupplierNum());//供应商编号
            sysWorkbenchAuditAgentVo.setStatus(1);//待审核
            sysWorkbenchAuditAgentVo.setReceiptContent("有单据待审核,请及时审核");

            feignService.insertAuditAgent(sysWorkbenchAuditAgentVo);

            return updateById(orderSupplierManagement);
        } else {
            throw new GlobalException("只能操作待提交的数据");
        }

    }

    /**
     * 修改供应商
     *
     * @param orderSupplierManagementVo
     * @return
     */
    @Override
    public boolean updateSupplierById(OrderSupplierManagementVo orderSupplierManagementVo) throws Exception {
        OrderSupplierManagement orderSupplierManagement = getById(orderSupplierManagementVo.getId());
        if (orderSupplierManagement.getAuditStatus() == 2 || orderSupplierManagement.getAuditStatus() == 5) {
            List<OrderSupplierManagement> list = list();
            List<OrderSupplierManagement> collect = list.stream().filter(entity -> entity.getId() != orderSupplierManagementVo.getId()).collect(Collectors.toList());
            for (OrderSupplierManagement entity : collect) {
                if (entity.getSupplierAbbreviation().equals(orderSupplierManagementVo.getSupplierAbbreviation())) {
                    throw new GlobalException("供应商简称已经存在");
                }
            }
            BeanUtils.copyProperties(orderSupplierManagementVo, orderSupplierManagement);
            orderSupplierManagement.setSupplierLevel(Integer.parseInt(orderSupplierManagementVo.getSupplierLevel()));
            orderSupplierManagement.setAscriptionBy(Long.parseLong(orderSupplierManagementVo.getAscriptionBy()));

            //调用审核
            if (orderSupplierManagement.getAuditStatus() == 5) {
                SysAuditHistoryVo sysAuditHistoryVo = new SysAuditHistoryVo();
                String perms = "order:purchase:supplier:examine";
                String auditDoc = orderSupplierManagement.getSupplierNum();
                sysAuditHistoryVo.setAuditDoc(auditDoc);
                sysAuditHistoryVo.setPerms(perms);
                AjaxResult history = feignService.editHistory(sysAuditHistoryVo);
                String data = JSON.parseObject(JSON.toJSONString(history.get("msg")), String.class);
                if ("操作成功".equals(data)) {
                    orderSupplierManagement.setAuditStatus(2);
                    //mq发送消息
                    OrderSupplierManagementMqDto orderSupplierManagementMqDto = new OrderSupplierManagementMqDto();
                    BeanUtils.copyProperties(orderSupplierManagement, orderSupplierManagementMqDto);
                    VariousMqUtil.orderSupplierManagementMqSend(orderSupplierManagementMqDto);

                    //修改审核代办状态为已处理
                    feignService.updateStatus(3,orderSupplierManagement.getSupplierNum(),"供应商管理");//

                    return updateById(orderSupplierManagement);
                } else {
                    return false;
                }



            }
            //mq发送消息
            OrderSupplierManagementMqDto orderSupplierManagementMqDto = new OrderSupplierManagementMqDto();
            BeanUtils.copyProperties(orderSupplierManagement, orderSupplierManagementMqDto);
            VariousMqUtil.orderSupplierManagementMqSend(orderSupplierManagementMqDto);
            return updateById(orderSupplierManagement);
        } else {
            throw new GlobalException("只能修改待提交或者未通过的数据");
        }
    }

    /**
     * 供应商审核
     *
     * @param orderReviewVo
     * @return
     */
    @Override
    public boolean supplierReview(OrderReviewVo orderReviewVo) {
        OrderSupplierManagement orderSupplierManagement = getById(orderReviewVo.getId());
        if (orderSupplierManagement.getAuditStatus() == 1 || orderSupplierManagement.getAuditStatus() == 3) {
            String perms = "order:purchase:supplier:examine";
            //获取菜单id
            int isAdopt = orderReviewVo.getIsAdopt();
            String auditDoc = orderSupplierManagement.getSupplierNum();
            String auditRemarks = orderReviewVo.getReviewComments();
            Long userId = SecurityUtils.getUserId();
            AjaxResult sequence = feignService.getSequenceTwo(perms, 2, isAdopt, auditRemarks, auditDoc, userId);
            Integer data = JSON.parseObject(JSON.toJSONString(sequence.get("data")), Integer.class);
            if (data == null) {
                throw new GlobalException("未对该审核进行配置");
            }
            //1:通过，2：审核中，3：没权限 4:该人已经审核过
            if (orderReviewVo.getIsAdopt() == 1) {
                if (data == 1) {
                    orderSupplierManagement.setAuditStatus(4);
                    //修改审核代办状态为已处理
                    feignService.updateStatus(3,auditDoc,"供应商管理");

                    return updateById(orderSupplierManagement);
                } else if (data == 2) {
                    orderSupplierManagement.setAuditStatus(3);
                    return updateById(orderSupplierManagement);
                } else if (data == 3) {
                    throw new GlobalException("没有审核权限");
                } else {
                    throw new GlobalException("该用户已经审核过");
                }
            } else {
                if (data == 1 || data == 2) {
                    orderSupplierManagement.setAuditStatus(5);

                    //新增审核代办
                    SysWorkbenchAuditAgentVo sysWorkbenchAuditAgentVo = new SysWorkbenchAuditAgentVo();

                    sysWorkbenchAuditAgentVo.setReceiptName("供应商管理");
                    sysWorkbenchAuditAgentVo.setDocConfig("order:purchase:supplier:examine");
                    sysWorkbenchAuditAgentVo.setReceiptNumber(orderSupplierManagement.getSupplierNum());//供应商编号
                    sysWorkbenchAuditAgentVo.setStatus(2);//待处理
                    sysWorkbenchAuditAgentVo.setPassFlag("1");
                    sysWorkbenchAuditAgentVo.setCreateName(orderSupplierManagement.getCreateBy());
                    sysWorkbenchAuditAgentVo.setReceiptContent("单据审核未通过,请及时查看");

                    feignService.insertAuditAgent(sysWorkbenchAuditAgentVo);

                    return updateById(orderSupplierManagement);
                } else if (data == 3) {
                    throw new GlobalException("没有审核权限");
                } else {
                    throw new GlobalException("该用户已经审核过");
                }
            }
        } else {
            throw new GlobalException("只能对待审核和审核中的数据进行处理");
        }
    }
}
